package com.gexiao.config;

import com.gexiao.handler.MyHandlerInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.*;

/**
 * 子容器，只扫描@controller注解
 */
@ComponentScan(value = "com.gexiao"
        ,includeFilters = {@ComponentScan.Filter(classes = Controller.class)}
        ,useDefaultFilters = false)
@EnableWebMvc
public class AppConfig implements WebMvcConfigurer {

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp();
    }

    /**
     * 此方法用来专门注册一个Handler，来处理静态资源的，例如：图片，js，css等。
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations("/WEB-INF/static/", "classpath:/static/")
                .setCachePeriod(31556926);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyHandlerInterceptor());
    }
}
